﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using CronusModel;

namespace Cronus.ViewModel
{
    /// <summary>
    /// Provides a summary of time worked on a given project.
    /// </summary>
    public class ProjectSummary : SummaryBase
    {
        //*** Constants ***//
        //*** Static ***//
        //*** Member Variables ***//
        private DataModel _DataModel;
        private string _ProjectName;

        //*** Properties ***//
        //*** Constructors ***//
        /// <summary>
        /// Default constructor.  Returns summary of all projects, not a specific project.
        /// </summary>
        public ProjectSummary(DataModel aDataModel) : this(aDataModel, String.Empty)
        {
        }

        /// <summary>
        /// Constructor that takes the project name to return a summary of.
        /// </summary>
        /// <param name="strTaskName">Name of the project to provide a summary of.</param>
        public ProjectSummary(DataModel aDataModel, string strProjectName)
        {
            _DataModel = aDataModel;
            _ProjectName = strProjectName;
        }

        //*** Abstract Methods ***//
        //*** Methods ***//
        /// <summary>
        /// Query for the total amount of time associated with this project in the given time span.
        /// </summary>
        /// <param name="aStartDate">Start of the time period to query on.</param>
        /// <param name="anEndDate">End of the time period to query on.</param>
        /// <returns>Total number of hours in the time span.</returns>
        protected override double QueryForHoursInRange(DateTime aStartDate, DateTime anEndDate)
        {
            QueryProjectInformation aProjectQuery = new QueryProjectInformation(_DataModel);
            TimeSpan allTimeInRange;

            allTimeInRange = aProjectQuery.GetProjectHoursInDateRange(_ProjectName, aStartDate, anEndDate);

            return allTimeInRange.TotalHours;
        }
    }
}
